#include <iostream>
#include <vector>
#include<unordered_set>
using namespace std;
class Solution
{
public:
    /**
     * @brief 
     * 1 <= sentence.length <= 150
sentence 由英文字母和空格组成
sentence 不含前导或尾随空格
sentence 中的所有单词由单个空格分隔
     * 
     * @param sentence 
     * @return string 
     */
    string toGoatLatin(string sentence)
    {
        unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};

        int n = sentence.size();
        int i = 0, cnt = 1;
        string ans;

        while (i < n)
        {
            int j = i;
            /**
             * @brief 空格
             * 
             */
            while (j < n && sentence[j] != ' ')
            {
                ++j;
            }

            ++cnt;
            if (cnt != 2)
            {
                ans += ' ';
            }
            if (vowels.count(sentence[i]))
            {
                ans += sentence.substr(i, j - i) + 'm' + string(cnt, 'a');
            }
            else
            {
                ans += sentence.substr(i + 1, j - i - 1) + sentence[i] + 'm' + string(cnt, 'a');
            }

            i = j + 1;
        }

        return ans;
    }
};
int main()
{

    system("pause");
    return 0;
}
